//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

//====================================================
// Created     : 2004-1-6
// Author      : FengTao
// Description : Some test functions for the hal of x86 in core
//====================================================
#include <core.h>
#include "testx86.h"

EXTERN_C void CDECL TestKSetup1()
{
    TestPaging1();
    TestSegment1();
}

EXTERN_C void CDECL TestSegment1()
{
    kprintf("======\n");
    GdtPointer gdtPointer = {0, 0};
    ASM("sgdt   %0;": :"m"(gdtPointer));
    kprintf("GdtPointer.limit is %x\n", gdtPointer.u16Limit);
    GdtPointer idtPointer = {0, 0};
    ASM("sidt   %0;": :"m"(idtPointer));
    kprintf("idtPointer.limit is %x\n", idtPointer.u16Limit);
    if ((void *)g_idt == (void *)idtPointer.u32Base)
        kprintf("idt Register is ok!\n");
    else
        kprintf("ERROR idt Register!\n");
    GdtPointer ldtPointer = {1, 1};
    ASM("sldt   %0;": :"m"(ldtPointer));
    kprintf("ldtPointer.limit is %x\n", ldtPointer.u16Limit);
    kprintf("ldtPointer.base is %x\n", ldtPointer.u32Base);

    UInt16 selector = 0;
    ASM("str   %0;": :"m"(selector));
    kprintf("register TR is %x\n", selector);
}

EXTERN_C void CDECL TestInterrupt1()
{
    kprintf("currentIpl is %x\n", g_currentIpl);
//    long bTag = 1;
//    for(uint_t i = 0; i < NUMBEROF_IPLS + 1; i++)
//        if(g_irqsTable[i] != 0) {
//            bTag = 0;
//            break;
//        }
//    if (bTag) kprintf("g_irqsTable is ok!\n");
//    else kprintf("ERROR g_irqsTable\n");
}
